********************************************************************************
**  TITLE:      ca2015_ipsos_exit					                          **  
**  AUTHORS:    P. Mongrain, N. Fréchet, B. Thompson Collart, and Y. Dufresne **
**  DATA:       2015 Canada General Election Exit Poll		                  **
**	DATE:		February 2025	 					                          **	
**  VERSION:	Stata 17					                                  **	
********************************************************************************

* Note: The data file needs to be downloaded from its original source (see the "surveys.text" file)

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "ca2015_ipsos_exit", replace

* Open the dataset

import spss using "2015 Canada General Election Exit Poll.sav", clear case(lower)

* Election

gen election = "ca2015"

* Type of survey

gen type = "exit"

* Type of expectation item

gen probability = 0

* Respondent ID

gen responseid = id

* Survey weight

merge 1:1 election responseid using ca2015_exit_weight
drop _merge


***********************
** DISTRICT OUTCOMES **
***********************

decode seat, generate(seat_str)

gen str district_name = substr(seat_str,9,100)

gen str seat_code = substr(seat_str,1,5)
replace seat_code = "" if seat_str == "Not specified"
destring seat_code, gen(district_code)

* Election outcome in each district

gen district_outcome = .

replace district_outcome = 2 if district_code == 10001
replace district_outcome = 2 if district_code == 10002
replace district_outcome = 2 if district_code == 10003
replace district_outcome = 2 if district_code == 10004
replace district_outcome = 2 if district_code == 10005
replace district_outcome = 2 if district_code == 10006
replace district_outcome = 2 if district_code == 10007
replace district_outcome = 2 if district_code == 11001
replace district_outcome = 2 if district_code == 11002
replace district_outcome = 2 if district_code == 11003
replace district_outcome = 2 if district_code == 11004
replace district_outcome = 2 if district_code == 12001
replace district_outcome = 2 if district_code == 12002
replace district_outcome = 2 if district_code == 12003
replace district_outcome = 2 if district_code == 12004
replace district_outcome = 2 if district_code == 12005
replace district_outcome = 2 if district_code == 12006
replace district_outcome = 2 if district_code == 12007
replace district_outcome = 2 if district_code == 12008
replace district_outcome = 2 if district_code == 12009
replace district_outcome = 2 if district_code == 12010
replace district_outcome = 2 if district_code == 12011
replace district_outcome = 2 if district_code == 13001
replace district_outcome = 2 if district_code == 13002
replace district_outcome = 2 if district_code == 13003
replace district_outcome = 2 if district_code == 13004
replace district_outcome = 2 if district_code == 13005
replace district_outcome = 2 if district_code == 13006
replace district_outcome = 2 if district_code == 13007
replace district_outcome = 2 if district_code == 13008
replace district_outcome = 2 if district_code == 13009
replace district_outcome = 2 if district_code == 13010
replace district_outcome = 3 if district_code == 24001
replace district_outcome = 3 if district_code == 24002
replace district_outcome = 2 if district_code == 24003
replace district_outcome = 2 if district_code == 24004
replace district_outcome = 2 if district_code == 24005
replace district_outcome = 2 if district_code == 24006
replace district_outcome = 1 if district_code == 24007
replace district_outcome = 1 if district_code == 24008
replace district_outcome = 4 if district_code == 24009
replace district_outcome = 1 if district_code == 24010
replace district_outcome = 3 if district_code == 24011
replace district_outcome = 3 if district_code == 24012
replace district_outcome = 2 if district_code == 24013
replace district_outcome = 4 if district_code == 24014
replace district_outcome = 2 if district_code == 24015
replace district_outcome = 2 if district_code == 24016
replace district_outcome = 2 if district_code == 24017
replace district_outcome = 3 if district_code == 24018
replace district_outcome = 1 if district_code == 24019
replace district_outcome = 1 if district_code == 24020
replace district_outcome = 2 if district_code == 24021
replace district_outcome = 2 if district_code == 24022
replace district_outcome = 2 if district_code == 24023
replace district_outcome = 2 if district_code == 24024
replace district_outcome = 3 if district_code == 24025
replace district_outcome = 2 if district_code == 24026
replace district_outcome = 2 if district_code == 24027
replace district_outcome = 3 if district_code == 24028
replace district_outcome = 2 if district_code == 24029
replace district_outcome = 2 if district_code == 24030
replace district_outcome = 4 if district_code == 24031
replace district_outcome = 3 if district_code == 24032
replace district_outcome = 4 if district_code == 24033
replace district_outcome = 2 if district_code == 24034
replace district_outcome = 1 if district_code == 24035
replace district_outcome = 2 if district_code == 24036
replace district_outcome = 2 if district_code == 24037
replace district_outcome = 2 if district_code == 24038
replace district_outcome = 3 if district_code == 24039
replace district_outcome = 2 if district_code == 24040
replace district_outcome = 2 if district_code == 24041
replace district_outcome = 1 if district_code == 24042
replace district_outcome = 3 if district_code == 24043
replace district_outcome = 2 if district_code == 24044
replace district_outcome = 1 if district_code == 24045
replace district_outcome = 4 if district_code == 24046
replace district_outcome = 1 if district_code == 24047
replace district_outcome = 4 if district_code == 24048
replace district_outcome = 2 if district_code == 24049
replace district_outcome = 4 if district_code == 24050
replace district_outcome = 1 if district_code == 24051
replace district_outcome = 2 if district_code == 24052
replace district_outcome = 2 if district_code == 24053
replace district_outcome = 3 if district_code == 24054
replace district_outcome = 2 if district_code == 24055
replace district_outcome = 2 if district_code == 24056
replace district_outcome = 2 if district_code == 24057
replace district_outcome = 1 if district_code == 24058
replace district_outcome = 2 if district_code == 24059
replace district_outcome = 4 if district_code == 24060
replace district_outcome = 1 if district_code == 24061
replace district_outcome = 2 if district_code == 24062
replace district_outcome = 4 if district_code == 24063
replace district_outcome = 3 if district_code == 24064
replace district_outcome = 2 if district_code == 24065
replace district_outcome = 3 if district_code == 24066
replace district_outcome = 2 if district_code == 24067
replace district_outcome = 2 if district_code == 24068
replace district_outcome = 2 if district_code == 24069
replace district_outcome = 2 if district_code == 24070
replace district_outcome = 3 if district_code == 24071
replace district_outcome = 2 if district_code == 24072
replace district_outcome = 3 if district_code == 24073
replace district_outcome = 2 if district_code == 24074
replace district_outcome = 4 if district_code == 24075
replace district_outcome = 3 if district_code == 24076
replace district_outcome = 2 if district_code == 24077
replace district_outcome = 2 if district_code == 24078
replace district_outcome = 2 if district_code == 35001
replace district_outcome = 3 if district_code == 35002
replace district_outcome = 2 if district_code == 35003
replace district_outcome = 1 if district_code == 35004
replace district_outcome = 1 if district_code == 35005
replace district_outcome = 2 if district_code == 35006
replace district_outcome = 2 if district_code == 35007
replace district_outcome = 2 if district_code == 35008
replace district_outcome = 2 if district_code == 35009
replace district_outcome = 2 if district_code == 35010
replace district_outcome = 2 if district_code == 35011
replace district_outcome = 2 if district_code == 35012
replace district_outcome = 1 if district_code == 35013
replace district_outcome = 1 if district_code == 35014
replace district_outcome = 2 if district_code == 35015
replace district_outcome = 2 if district_code == 35016
replace district_outcome = 1 if district_code == 35017
replace district_outcome = 2 if district_code == 35018
replace district_outcome = 2 if district_code == 35019
replace district_outcome = 2 if district_code == 35020
replace district_outcome = 2 if district_code == 35021
replace district_outcome = 1 if district_code == 35022
replace district_outcome = 1 if district_code == 35023
replace district_outcome = 2 if district_code == 35024
replace district_outcome = 1 if district_code == 35025
replace district_outcome = 3 if district_code == 35026
replace district_outcome = 2 if district_code == 35027
replace district_outcome = 2 if district_code == 35028
replace district_outcome = 2 if district_code == 35029
replace district_outcome = 1 if district_code == 35030
replace district_outcome = 2 if district_code == 35031
replace district_outcome = 2 if district_code == 35032
replace district_outcome = 1 if district_code == 35033
replace district_outcome = 1 if district_code == 35034
replace district_outcome = 3 if district_code == 35035
replace district_outcome = 2 if district_code == 35036
replace district_outcome = 3 if district_code == 35037
replace district_outcome = 2 if district_code == 35038
replace district_outcome = 2 if district_code == 35039
replace district_outcome = 1 if district_code == 35040
replace district_outcome = 2 if district_code == 35041
replace district_outcome = 2 if district_code == 35042
replace district_outcome = 2 if district_code == 35043
replace district_outcome = 2 if district_code == 35044
replace district_outcome = 2 if district_code == 35045
replace district_outcome = 1 if district_code == 35046
replace district_outcome = 2 if district_code == 35047
replace district_outcome = 1 if district_code == 35048
replace district_outcome = 1 if district_code == 35049
replace district_outcome = 1 if district_code == 35050
replace district_outcome = 3 if district_code == 35051
replace district_outcome = 2 if district_code == 35052
replace district_outcome = 2 if district_code == 35053
replace district_outcome = 2 if district_code == 35054
replace district_outcome = 2 if district_code == 35055
replace district_outcome = 1 if district_code == 35056
replace district_outcome = 1 if district_code == 35057
replace district_outcome = 2 if district_code == 35058
replace district_outcome = 2 if district_code == 35059
replace district_outcome = 2 if district_code == 35060
replace district_outcome = 2 if district_code == 35061
replace district_outcome = 2 if district_code == 35062
replace district_outcome = 2 if district_code == 35063
replace district_outcome = 2 if district_code == 35064
replace district_outcome = 2 if district_code == 35065
replace district_outcome = 2 if district_code == 35066
replace district_outcome = 1 if district_code == 35067
replace district_outcome = 1 if district_code == 35068
replace district_outcome = 2 if district_code == 35069
replace district_outcome = 2 if district_code == 35070
replace district_outcome = 2 if district_code == 35071
replace district_outcome = 2 if district_code == 35072
replace district_outcome = 2 if district_code == 35073
replace district_outcome = 1 if district_code == 35074
replace district_outcome = 2 if district_code == 35075
replace district_outcome = 2 if district_code == 35076
replace district_outcome = 2 if district_code == 35077
replace district_outcome = 2 if district_code == 35078
replace district_outcome = 2 if district_code == 35079
replace district_outcome = 1 if district_code == 35080
replace district_outcome = 2 if district_code == 35081
replace district_outcome = 1 if district_code == 35082
replace district_outcome = 1 if district_code == 35083
replace district_outcome = 2 if district_code == 35084
replace district_outcome = 2 if district_code == 35085
replace district_outcome = 1 if district_code == 35086
replace district_outcome = 2 if district_code == 35087
replace district_outcome = 1 if district_code == 35088
replace district_outcome = 2 if district_code == 35089
replace district_outcome = 2 if district_code == 35090
replace district_outcome = 1 if district_code == 35091
replace district_outcome = 2 if district_code == 35092
replace district_outcome = 2 if district_code == 35093
replace district_outcome = 2 if district_code == 35094
replace district_outcome = 2 if district_code == 35095
replace district_outcome = 2 if district_code == 35096
replace district_outcome = 2 if district_code == 35097
replace district_outcome = 2 if district_code == 35098
replace district_outcome = 1 if district_code == 35099
replace district_outcome = 1 if district_code == 35100
replace district_outcome = 2 if district_code == 35101
replace district_outcome = 1 if district_code == 35102
replace district_outcome = 2 if district_code == 35103
replace district_outcome = 1 if district_code == 35104
replace district_outcome = 2 if district_code == 35105
replace district_outcome = 2 if district_code == 35106
replace district_outcome = 3 if district_code == 35107
replace district_outcome = 2 if district_code == 35108
replace district_outcome = 2 if district_code == 35109
replace district_outcome = 2 if district_code == 35110
replace district_outcome = 2 if district_code == 35111
replace district_outcome = 2 if district_code == 35112
replace district_outcome = 1 if district_code == 35113
replace district_outcome = 2 if district_code == 35114
replace district_outcome = 2 if district_code == 35115
replace district_outcome = 3 if district_code == 35116
replace district_outcome = 3 if district_code == 35117
replace district_outcome = 2 if district_code == 35118
replace district_outcome = 1 if district_code == 35119
replace district_outcome = 2 if district_code == 35120
replace district_outcome = 2 if district_code == 35121
replace district_outcome = 1 if district_code == 46001
replace district_outcome = 2 if district_code == 46002
replace district_outcome = 3 if district_code == 46003
replace district_outcome = 1 if district_code == 46004
replace district_outcome = 3 if district_code == 46005
replace district_outcome = 2 if district_code == 46006
replace district_outcome = 1 if district_code == 46007
replace district_outcome = 1 if district_code == 46008
replace district_outcome = 2 if district_code == 46009
replace district_outcome = 1 if district_code == 46010
replace district_outcome = 2 if district_code == 46011
replace district_outcome = 2 if district_code == 46012
replace district_outcome = 2 if district_code == 46013
replace district_outcome = 2 if district_code == 46014
replace district_outcome = 1 if district_code == 47001
replace district_outcome = 1 if district_code == 47002
replace district_outcome = 3 if district_code == 47003
replace district_outcome = 1 if district_code == 47004
replace district_outcome = 1 if district_code == 47005
replace district_outcome = 1 if district_code == 47006
replace district_outcome = 3 if district_code == 47007
replace district_outcome = 1 if district_code == 47008
replace district_outcome = 2 if district_code == 47009
replace district_outcome = 1 if district_code == 47010
replace district_outcome = 1 if district_code == 47011
replace district_outcome = 3 if district_code == 47012
replace district_outcome = 1 if district_code == 47013
replace district_outcome = 1 if district_code == 47014
replace district_outcome = 1 if district_code == 48001
replace district_outcome = 1 if district_code == 48002
replace district_outcome = 1 if district_code == 48003
replace district_outcome = 2 if district_code == 48004
replace district_outcome = 1 if district_code == 48005
replace district_outcome = 1 if district_code == 48006
replace district_outcome = 1 if district_code == 48007
replace district_outcome = 1 if district_code == 48008
replace district_outcome = 1 if district_code == 48009
replace district_outcome = 1 if district_code == 48010
replace district_outcome = 1 if district_code == 48011
replace district_outcome = 1 if district_code == 48012
replace district_outcome = 2 if district_code == 48013
replace district_outcome = 2 if district_code == 48014
replace district_outcome = 1 if district_code == 48015
replace district_outcome = 1 if district_code == 48016
replace district_outcome = 2 if district_code == 48017
replace district_outcome = 1 if district_code == 48018
replace district_outcome = 3 if district_code == 48019
replace district_outcome = 1 if district_code == 48020
replace district_outcome = 1 if district_code == 48021
replace district_outcome = 1 if district_code == 48022
replace district_outcome = 1 if district_code == 48023
replace district_outcome = 1 if district_code == 48024
replace district_outcome = 1 if district_code == 48025
replace district_outcome = 1 if district_code == 48026
replace district_outcome = 1 if district_code == 48027
replace district_outcome = 1 if district_code == 48028
replace district_outcome = 1 if district_code == 48029
replace district_outcome = 1 if district_code == 48030
replace district_outcome = 1 if district_code == 48031
replace district_outcome = 1 if district_code == 48032
replace district_outcome = 1 if district_code == 48033
replace district_outcome = 1 if district_code == 48034
replace district_outcome = 1 if district_code == 59001
replace district_outcome = 2 if district_code == 59002
replace district_outcome = 3 if district_code == 59003
replace district_outcome = 1 if district_code == 59004
replace district_outcome = 1 if district_code == 59005
replace district_outcome = 1 if district_code == 59006
replace district_outcome = 2 if district_code == 59007
replace district_outcome = 2 if district_code == 59008
replace district_outcome = 3 if district_code == 59009
replace district_outcome = 3 if district_code == 59010
replace district_outcome = 2 if district_code == 59011
replace district_outcome = 2 if district_code == 59012
replace district_outcome = 1 if district_code == 59013
replace district_outcome = 2 if district_code == 59014
replace district_outcome = 3 if district_code == 59015
replace district_outcome = 1 if district_code == 59016
replace district_outcome = 2 if district_code == 59017
replace district_outcome = 3 if district_code == 59018
replace district_outcome = 3 if district_code == 59019
replace district_outcome = 1 if district_code == 59020
replace district_outcome = 2 if district_code == 59021
replace district_outcome = 2 if district_code == 59022
replace district_outcome = 3 if district_code == 59023
replace district_outcome = 1 if district_code == 59024
replace district_outcome = 1 if district_code == 59025
replace district_outcome = 3 if district_code == 59026
replace district_outcome = 88 if district_code == 59027
replace district_outcome = 3 if district_code == 59028
replace district_outcome = 3 if district_code == 59029
replace district_outcome = 1 if district_code == 59030
replace district_outcome = 2 if district_code == 59031
replace district_outcome = 2 if district_code == 59032
replace district_outcome = 2 if district_code == 59033
replace district_outcome = 2 if district_code == 59034
replace district_outcome = 3 if district_code == 59035
replace district_outcome = 2 if district_code == 59036
replace district_outcome = 3 if district_code == 59037
replace district_outcome = 3 if district_code == 59038
replace district_outcome = 2 if district_code == 59039
replace district_outcome = 2 if district_code == 59040
replace district_outcome = 3 if district_code == 59041
replace district_outcome = 2 if district_code == 59042
replace district_outcome = 2 if district_code == 60001
replace district_outcome = 2 if district_code == 61001
replace district_outcome = 2 if district_code == 62001

label define outcome 1 "Conservative Party of Canada" 2 "Liberal Party of Canada" 3 "New Democratic Party of Canada" 4 "Bloc Québécois" 88 "Other"
label values district_outcome outcome


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 38.1 if district_code == 10001
replace margin = 71.7 if district_code == 10002
replace margin = 56.5 if district_code == 10003
replace margin = 57.4 if district_code == 10004
replace margin = 61.7 if district_code == 10005
replace margin = 1.4 if district_code == 10006
replace margin = 21.1 if district_code == 10007
replace margin = 48.9 if district_code == 11001
replace margin = 33.1 if district_code == 11002
replace margin = 20.3 if district_code == 11003
replace margin = 44.5 if district_code == 11004
replace margin = 59.9 if district_code == 12001
replace margin = 32.7 if district_code == 12002
replace margin = 37.3 if district_code == 12003
replace margin = 33.8 if district_code == 12004
replace margin = 15.6 if district_code == 12005
replace margin = 53 if district_code == 12006
replace margin = 52.2 if district_code == 12007
replace margin = 13.6 if district_code == 12008
replace margin = 34.4 if district_code == 12009
replace margin = 60.1 if district_code == 12010
replace margin = 36.9 if district_code == 12011
replace margin = 11.3 if district_code == 13001
replace margin = 53.9 if district_code == 13002
replace margin = 20.8 if district_code == 13003
replace margin = 3.8 if district_code == 13004
replace margin = 29.8 if district_code == 13005
replace margin = 13 if district_code == 13006
replace margin = 36.3 if district_code == 13007
replace margin = 5.4 if district_code == 13008
replace margin = 18.3 if district_code == 13009
replace margin = 9.6 if district_code == 13010
replace margin = 4.9 if district_code == 24001
replace margin = 11.9 if district_code == 24002
replace margin = 16.8 if district_code == 24003
replace margin = 20.5 if district_code == 24004
replace margin = 18.5 if district_code == 24005
replace margin = 18.5 if district_code == 24006
replace margin = 36.6 if district_code == 24007
replace margin = 5.1 if district_code == 24008
replace margin = 15.7 if district_code == 24009
replace margin = 30.2 if district_code == 24010
replace margin = 1.7 if district_code == 24011
replace margin = 16.4 if district_code == 24012
replace margin = 5.4 if district_code == 24013
replace margin = 0.4 if district_code == 24014
replace margin = 36.9 if district_code == 24015
replace margin = 19.4 if district_code == 24016
replace margin = 25.7 if district_code == 24017
replace margin = 15.1 if district_code == 24018
replace margin = 19 if district_code == 24019
replace margin = 6.6 if district_code == 24020
replace margin = 14.7 if district_code == 24021
replace margin = 1.4 if district_code == 24022
replace margin = 9.5 if district_code == 24023
replace margin = 33.3 if district_code == 24024
replace margin = 3.9 if district_code == 24025
replace margin = 6.2 if district_code == 24026
replace margin = 27.2 if district_code == 24027
replace margin = 1 if district_code == 24028
replace margin = 40.1 if district_code == 24029
replace margin = 19.9 if district_code == 24030
replace margin = 5.1 if district_code == 24031
replace margin = 0.7 if district_code == 24032
replace margin = 5 if district_code == 24033
replace margin = 10.2 if district_code == 24034
replace margin = 4.8 if district_code == 24035
replace margin = 46.7 if district_code == 24036
replace margin = 14.9 if district_code == 24037
replace margin = 2.4 if district_code == 24038
replace margin = 9.6 if district_code == 24039
replace margin = 27.9 if district_code == 24040
replace margin = 8.4 if district_code == 24041
replace margin = 28.4 if district_code == 24042
replace margin = 1.2 if district_code == 24043
replace margin = 7.7 if district_code == 24044
replace margin = 29 if district_code == 24045
replace margin = 11.9 if district_code == 24046
replace margin = 7.3 if district_code == 24047
replace margin = 1.4 if district_code == 24048
replace margin = 4.1 if district_code == 24049
replace margin = 9.3 if district_code == 24050
replace margin = 0.6 if district_code == 24051
replace margin = 12.5 if district_code == 24052
replace margin = 35.9 if district_code == 24053
replace margin = 10.6 if district_code == 24054
replace margin = 26.1 if district_code == 24055
replace margin = 38.7 if district_code == 24056
replace margin = 32 if district_code == 24057
replace margin = 21.9 if district_code == 24058
replace margin = 1.9 if district_code == 24059
replace margin = 7.4 if district_code == 24060
replace margin = 6.9 if district_code == 24061
replace margin = 2.9 if district_code == 24062
replace margin = 1.9 if district_code == 24063
replace margin = 28.1 if district_code == 24064
replace margin = 17.4 if district_code == 24065
replace margin = 1.1 if district_code == 24066
replace margin = 4.1 if district_code == 24067
replace margin = 42.1 if district_code == 24068
replace margin = 49.9 if district_code == 24069
replace margin = 20.7 if district_code == 24070
replace margin = 1.3 if district_code == 24071
replace margin = 15.3 if district_code == 24072
replace margin = 7.6 if district_code == 24073
replace margin = 24.3 if district_code == 24074
replace margin = 5 if district_code == 24075
replace margin = 1.6 if district_code == 24076
replace margin = 27.4 if district_code == 24077
replace margin = 25.2 if district_code == 24078
replace margin = 21.5 if district_code == 35001
replace margin = 5.8 if district_code == 35002
replace margin = 2.1 if district_code == 35003
replace margin = 9.3 if district_code == 35004
replace margin = 0.2 if district_code == 35005
replace margin = 16.5 if district_code == 35006
replace margin = 18.6 if district_code == 35007
replace margin = 15 if district_code == 35008
replace margin = 28.8 if district_code == 35009
replace margin = 15.4 if district_code == 35010
replace margin = 17.1 if district_code == 35011
replace margin = 25.8 if district_code == 35012
replace margin = 10.2 if district_code == 35013
replace margin = 7.8 if district_code == 35014
replace margin = 3.5 if district_code == 35015
replace margin = 4.5 if district_code == 35016
replace margin = 4.5 if district_code == 35017
replace margin = 2.9 if district_code == 35018
replace margin = 28.6 if district_code == 35019
replace margin = 13.6 if district_code == 35020
replace margin = 16.2 if district_code == 35021
replace margin = 7.2 if district_code == 35022
replace margin = 9.4 if district_code == 35023
replace margin = 6.3 if district_code == 35024
replace margin = 18.2 if district_code == 35025
replace margin = 5.7 if district_code == 35026
replace margin = 15.4 if district_code == 35027
replace margin = 21.2 if district_code == 35028
replace margin = 39.4 if district_code == 35029
replace margin = 4.3 if district_code == 35030
replace margin = 16.9 if district_code == 35031
replace margin = 22.8 if district_code == 35032
replace margin = 7.5 if district_code == 35033
replace margin = 13.1 if district_code == 35034
replace margin = 12.2 if district_code == 35035
replace margin = 6.3 if district_code == 35036
replace margin = 2.4 if district_code == 35037
replace margin = 15.9 if district_code == 35038
replace margin = 0.5 if district_code == 35039
replace margin = 5.2 if district_code == 35040
replace margin = 12.1 if district_code == 35041
replace margin = 1.6 if district_code == 35042
replace margin = 3.2 if district_code == 35043
replace margin = 32.7 if district_code == 35044
replace margin = 18.4 if district_code == 35045
replace margin = 0.5 if district_code == 35046
replace margin = 5.6 if district_code == 35047
replace margin = 20.8 if district_code == 35048
replace margin = 14.1 if district_code == 35049
replace margin = 6.8 if district_code == 35050
replace margin = 6.3 if district_code == 35051
replace margin = 19.4 if district_code == 35052
replace margin = 10.5 if district_code == 35053
replace margin = 6.4 if district_code == 35054
replace margin = 23.4 if district_code == 35055
replace margin = 6 if district_code == 35056
replace margin = 4.9 if district_code == 35057
replace margin = 21.1 if district_code == 35058
replace margin = 18.9 if district_code == 35059
replace margin = 10.5 if district_code == 35060
replace margin = 6.5 if district_code == 35061
replace margin = 32.7 if district_code == 35062
replace margin = 7.4 if district_code == 35063
replace margin = 16.3 if district_code == 35064
replace margin = 2.6 if district_code == 35065
replace margin = 4.2 if district_code == 35066
replace margin = 7.6 if district_code == 35067
replace margin = 16.1 if district_code == 35068
replace margin = 5 if district_code == 35069
replace margin = 22.6 if district_code == 35070
replace margin = 3 if district_code == 35071
replace margin = 6.9 if district_code == 35072
replace margin = 3.4 if district_code == 35073
replace margin = 6.3 if district_code == 35074
replace margin = 4.1 if district_code == 35075
replace margin = 29.1 if district_code == 35076
replace margin = 35.8 if district_code == 35077
replace margin = 38.3 if district_code == 35078
replace margin = 25.9 if district_code == 35079
replace margin = 13.5 if district_code == 35080
replace margin = 1.8 if district_code == 35081
replace margin = 4.4 if district_code == 35082
replace margin = 5.4 if district_code == 35083
replace margin = 8.8 if district_code == 35084
replace margin = 12.1 if district_code == 35085
replace margin = 13.2 if district_code == 35086
replace margin = 3.6 if district_code == 35087
replace margin = 3.1 if district_code == 35088
replace margin = 5.6 if district_code == 35089
replace margin = 28.3 if district_code == 35090
replace margin = 7.7 if district_code == 35091
replace margin = 13.6 if district_code == 35092
replace margin = 13.9 if district_code == 35093
replace margin = 17.9 if district_code == 35094
replace margin = 33.5 if district_code == 35095
replace margin = 20.8 if district_code == 35096
replace margin = 32.9 if district_code == 35097
replace margin = 28.7 if district_code == 35098
replace margin = 8 if district_code == 35099
replace margin = 3.7 if district_code == 35100
replace margin = 27.4 if district_code == 35101
replace margin = 12.5 if district_code == 35102
replace margin = 19.6 if district_code == 35103
replace margin = 24.8 if district_code == 35104
replace margin = 14.4 if district_code == 35105
replace margin = 21.8 if district_code == 35106
replace margin = 8.1 if district_code == 35107
replace margin = 31.3 if district_code == 35108
replace margin = 2.2 if district_code == 35109
replace margin = 21.2 if district_code == 35110
replace margin = 4.9 if district_code == 35111
replace margin = 17.4 if district_code == 35112
replace margin = 14.4 if district_code == 35113
replace margin = 2.9 if district_code == 35114
replace margin = 16.4 if district_code == 35115
replace margin = 16 if district_code == 35116
replace margin = 26.1 if district_code == 35117
replace margin = 2.9 if district_code == 35118
replace margin = 12.5 if district_code == 35119
replace margin = 15.6 if district_code == 35120
replace margin = 46.8 if district_code == 35121
replace margin = 13 if district_code == 46001
replace margin = 13 if district_code == 46002
replace margin = 3 if district_code == 46003
replace margin = 16.8 if district_code == 46004
replace margin = 0.1 if district_code == 46005
replace margin = 2.8 if district_code == 46006
replace margin = 35.1 if district_code == 46007
replace margin = 21.4 if district_code == 46008
replace margin = 29.8 if district_code == 46009
replace margin = 20.5 if district_code == 46010
replace margin = 26.5 if district_code == 46011
replace margin = 53.6 if district_code == 46012
replace margin = 23.6 if district_code == 46013
replace margin = 31.5 if district_code == 46014
replace margin = 43.4 if district_code == 47001
replace margin = 54.3 if district_code == 47002
replace margin = 0.3 if district_code == 47003
replace margin = 46.1 if district_code == 47004
replace margin = 31.7 if district_code == 47005
replace margin = 21.3 if district_code == 47006
replace margin = 0.3 if district_code == 47007
replace margin = 14.5 if district_code == 47008
replace margin = 24.9 if district_code == 47009
replace margin = 11.4 if district_code == 47010
replace margin = 10 if district_code == 47011
replace margin = 6.7 if district_code == 47012
replace margin = 56.5 if district_code == 47013
replace margin = 39 if district_code == 47014
replace margin = 37.3 if district_code == 48001
replace margin = 71.5 if district_code == 48002
replace margin = 63.7 if district_code == 48003
replace margin = 1.2 if district_code == 48004
replace margin = 2.4 if district_code == 48005
replace margin = 12 if district_code == 48006
replace margin = 37.8 if district_code == 48007
replace margin = 44.1 if district_code == 48008
replace margin = 33.2 if district_code == 48009
replace margin = 28.7 if district_code == 48010
replace margin = 41.2 if district_code == 48011
replace margin = 30 if district_code == 48012
replace margin = 6.1 if district_code == 48013
replace margin = 2.2 if district_code == 48014
replace margin = 5.9 if district_code == 48015
replace margin = 17.7 if district_code == 48016
replace margin = 0.2 if district_code == 48017
replace margin = 19.7 if district_code == 48018
replace margin = 12.7 if district_code == 48019
replace margin = 14.4 if district_code == 48020
replace margin = 44.3 if district_code == 48021
replace margin = 62.3 if district_code == 48022
replace margin = 32.2 if district_code == 48023
replace margin = 58.3 if district_code == 48024
replace margin = 59.1 if district_code == 48025
replace margin = 36.3 if district_code == 48026
replace margin = 50.9 if district_code == 48027
replace margin = 55 if district_code == 48028
replace margin = 60.9 if district_code == 48029
replace margin = 55.7 if district_code == 48030
replace margin = 22.7 if district_code == 48031
replace margin = 43.5 if district_code == 48032
replace margin = 54.7 if district_code == 48033
replace margin = 58 if district_code == 48034
replace margin = 15.5 if district_code == 59001
replace margin = 6.5 if district_code == 59002
replace margin = 1.2 if district_code == 59003
replace margin = 5.1 if district_code == 59004
replace margin = 2.4 if district_code == 59005
replace margin = 8.5 if district_code == 59006
replace margin = 10.8 if district_code == 59007
replace margin = 3.3 if district_code == 59008
replace margin = 9.8 if district_code == 59009
replace margin = 12.2 if district_code == 59010
replace margin = 16.3 if district_code == 59011
replace margin = 17.6 if district_code == 59012
replace margin = 4.5 if district_code == 59013
replace margin = 6.4 if district_code == 59014
replace margin = 0.4 if district_code == 59015
replace margin = 9.1 if district_code == 59016
replace margin = 2.3 if district_code == 59017
replace margin = 9.7 if district_code == 59018
replace margin = 14.5 if district_code == 59019
replace margin = 9.4 if district_code == 59020
replace margin = 29.8 if district_code == 59021
replace margin = 2.5 if district_code == 59022
replace margin = 5.2 if district_code == 59023
replace margin = 27.6 if district_code == 59024
replace margin = 2.8 if district_code == 59025
replace margin = 7.7 if district_code == 59026
replace margin = 34.9 if district_code == 59027
replace margin = 26.3 if district_code == 59028
replace margin = 7.4 if district_code == 59029
replace margin = 2.5 if district_code == 59030
replace margin = 6.6 if district_code == 59031
replace margin = 15 if district_code == 59032
replace margin = 29.9 if district_code == 59033
replace margin = 36.1 if district_code == 59034
replace margin = 21.8 if district_code == 59035
replace margin = 17.1 if district_code == 59036
replace margin = 14 if district_code == 59037
replace margin = 17.9 if district_code == 59038
replace margin = 32.9 if district_code == 59039
replace margin = 14.9 if district_code == 59040
replace margin = 9.4 if district_code == 59041
replace margin = 28.4 if district_code == 59042
replace margin = 29.4 if district_code == 60001
replace margin = 17.9 if district_code == 61001
replace margin = 20.5 if district_code == 62001

* Effective number of electoral parties by district

gen enep = .

replace enep = 2.650755068 if district_code == 10001
replace enep = 1.460455253 if district_code == 10002
replace enep = 1.675664988 if district_code == 10003
replace enep = 1.799917564 if district_code == 10004
replace enep = 1.740634949 if district_code == 10005
replace enep = 2.338344405 if district_code == 10006
replace enep = 2.114857934 if district_code == 10007
replace enep = 2.149012529 if district_code == 11001
replace enep = 2.527818644 if district_code == 11002
replace enep = 2.742062415 if district_code == 11003
replace enep = 2.285061411 if district_code == 11004
replace enep = 1.718520148 if district_code == 12001
replace enep = 2.375054329 if district_code == 12002
replace enep = 2.08090994 if district_code == 12003
replace enep = 2.386543712 if district_code == 12004
replace enep = 2.462453737 if district_code == 12005
replace enep = 1.959335942 if district_code == 12006
replace enep = 1.852791972 if district_code == 12007
replace enep = 2.690189685 if district_code == 12008
replace enep = 2.475639705 if district_code == 12009
replace enep = 1.770281227 if district_code == 12010
replace enep = 2.121300187 if district_code == 12011
replace enep = 2.388972503 if district_code == 13001
replace enep = 1.945820572 if district_code == 13002
replace enep = 2.866298634 if district_code == 13003
replace enep = 2.96644359 if district_code == 13004
replace enep = 2.469648026 if district_code == 13005
replace enep = 2.732285229 if district_code == 13006
replace enep = 2.446968084 if district_code == 13007
replace enep = 2.777824075 if district_code == 13008
replace enep = 2.756681507 if district_code == 13009
replace enep = 2.706902059 if district_code == 13010
replace enep = 3.528668669 if district_code == 24001
replace enep = 3.304605298 if district_code == 24002
replace enep = 3.009845204 if district_code == 24003
replace enep = 3.327853468 if district_code == 24004
replace enep = 3.369646895 if district_code == 24005
replace enep = 3.872501752 if district_code == 24006
replace enep = 2.428221765 if district_code == 24007
replace enep = 4.06944094 if district_code == 24008
replace enep = 3.553470853 if district_code == 24009
replace enep = 2.987973407 if district_code == 24010
replace enep = 3.724491886 if district_code == 24011
replace enep = 3.372487918 if district_code == 24012
replace enep = 3.890218047 if district_code == 24013
replace enep = 4.191764859 if district_code == 24014
replace enep = 2.82843825 if district_code == 24015
replace enep = 3.365484933 if district_code == 24016
replace enep = 2.932568519 if district_code == 24017
replace enep = 3.254191399 if district_code == 24018
replace enep = 3.47316287 if district_code == 24019
replace enep = 3.918065416 if district_code == 24020
replace enep = 3.588190547 if district_code == 24021
replace enep = 3.922306944 if district_code == 24022
replace enep = 3.702222815 if district_code == 24023
replace enep = 2.698858653 if district_code == 24024
replace enep = 4.046305925 if district_code == 24025
replace enep = 3.300765778 if district_code == 24026
replace enep = 2.659369357 if district_code == 24027
replace enep = 3.740541107 if district_code == 24028
replace enep = 2.647800208 if district_code == 24029
replace enep = 2.673982683 if district_code == 24030
replace enep = 3.741744776 if district_code == 24031
replace enep = 4.006426308 if district_code == 24032
replace enep = 3.65817969 if district_code == 24033
replace enep = 3.718467396 if district_code == 24034
replace enep = 1.490464011 if district_code == 24035
replace enep = 2.178122502 if district_code == 24036
replace enep = 3.210211039 if district_code == 24037
replace enep = 3.697910311 if district_code == 24038
replace enep = 3.468958029 if district_code == 24039
replace enep = 3.172910955 if district_code == 24040
replace enep = 3.753767844 if district_code == 24041
replace enep = 3.000138006 if district_code == 24042
replace enep = 3.702661473 if district_code == 24043
replace enep = 3.850344798 if district_code == 24044
replace enep = 2.96672521 if district_code == 24045
replace enep = 3.350139868 if district_code == 24046
replace enep = 3.727907488 if district_code == 24047
replace enep = 3.722564698 if district_code == 24048
replace enep = 3.848107501 if district_code == 24049
replace enep = 3.657724749 if district_code == 24050
replace enep = 4.006956076 if district_code == 24051
replace enep = 2.476246604 if district_code == 24052
replace enep = 2.482621648 if district_code == 24053
replace enep = 3.085238983 if district_code == 24054
replace enep = 2.812812925 if district_code == 24055
replace enep = 2.421805941 if district_code == 24056
replace enep = 2.687962498 if district_code == 24057
replace enep = 3.328462683 if district_code == 24058
replace enep = 4.164185506 if district_code == 24059
replace enep = 3.82187027 if district_code == 24060
replace enep = 4.010411027 if district_code == 24061
replace enep = 3.732025632 if district_code == 24062
replace enep = 3.695873926 if district_code == 24063
replace enep = 3.008849025 if district_code == 24064
replace enep = 3.519676753 if district_code == 24065
replace enep = 4.064429334 if district_code == 24066
replace enep = 3.7242006 if district_code == 24067
replace enep = 2.306805075 if district_code == 24068
replace enep = 2.181734086 if district_code == 24069
replace enep = 3.580482076 if district_code == 24070
replace enep = 3.7236043 if district_code == 24071
replace enep = 3.64281473 if district_code == 24072
replace enep = 3.576768175 if district_code == 24073
replace enep = 3.237157387 if district_code == 24074
replace enep = 3.760769905 if district_code == 24075
replace enep = 3.903977763 if district_code == 24076
replace enep = 2.970055896 if district_code == 24077
replace enep = 3.289581894 if district_code == 24078
replace enep = 2.284471533 if district_code == 35001
replace enep = 3.010823912 if district_code == 35002
replace enep = 2.317626009 if district_code == 35003
replace enep = 2.713807309 if district_code == 35004
replace enep = 2.775172199 if district_code == 35005
replace enep = 2.565029921 if district_code == 35006
replace enep = 2.728498071 if district_code == 35007
replace enep = 2.680799843 if district_code == 35008
replace enep = 2.619343854 if district_code == 35009
replace enep = 2.697264434 if district_code == 35010
replace enep = 2.463818821 if district_code == 35011
replace enep = 2.388265021 if district_code == 35012
replace enep = 3.088974831 if district_code == 35013
replace enep = 2.617506406 if district_code == 35014
replace enep = 2.493255743 if district_code == 35015
replace enep = 2.808594299 if district_code == 35016
replace enep = 2.883024177 if district_code == 35017
replace enep = 2.632472603 if district_code == 35018
replace enep = 2.321047257 if district_code == 35019
replace enep = 2.410864319 if district_code == 35020
replace enep = 2.300172513 if district_code == 35021
replace enep = 2.646146681 if district_code == 35022
replace enep = 2.794654385 if district_code == 35023
replace enep = 2.354037881 if district_code == 35024
replace enep = 2.75534468 if district_code == 35025
replace enep = 2.91640419 if district_code == 35026
replace enep = 2.356345403 if district_code == 35027
replace enep = 2.464389571 if district_code == 35028
replace enep = 2.184130978 if district_code == 35029
replace enep = 2.755868622 if district_code == 35030
replace enep = 2.363027132 if district_code == 35031
replace enep = 2.963129776 if district_code == 35032
replace enep = 2.870989228 if district_code == 35033
replace enep = 2.932001032 if district_code == 35034
replace enep = 2.917067763 if district_code == 35035
replace enep = 3.089051167 if district_code == 35036
replace enep = 3.245846939 if district_code == 35037
replace enep = 2.8012303 if district_code == 35038
replace enep = 2.685955408 if district_code == 35039
replace enep = 2.654730996 if district_code == 35040
replace enep = 2.368624256 if district_code == 35041
replace enep = 3.101236773 if district_code == 35042
replace enep = 2.355013588 if district_code == 35043
replace enep = 2.56808639 if district_code == 35044
replace enep = 2.784111632 if district_code == 35045
replace enep = 2.622902661 if district_code == 35046
replace enep = 2.944788167 if district_code == 35047
replace enep = 2.714227165 if district_code == 35048
replace enep = 2.74092753 if district_code == 35049
replace enep = 2.512960594 if district_code == 35050
replace enep = 3.161145726 if district_code == 35051
replace enep = 2.669122259 if district_code == 35052
replace enep = 2.799685315 if district_code == 35053
replace enep = 2.329210631 if district_code == 35054
replace enep = 2.346475945 if district_code == 35055
replace enep = 2.300913463 if district_code == 35056
replace enep = 2.618884251 if district_code == 35057
replace enep = 2.371837747 if district_code == 35058
replace enep = 2.343511987 if district_code == 35059
replace enep = 2.440423169 if district_code == 35060
replace enep = 2.473545432 if district_code == 35061
replace enep = 2.301919801 if district_code == 35062
replace enep = 2.497789456 if district_code == 35063
replace enep = 2.426071535 if district_code == 35064
replace enep = 2.53968254 if district_code == 35065
replace enep = 3.169692667 if district_code == 35066
replace enep = 2.936236684 if district_code == 35067
replace enep = 2.777546316 if district_code == 35068
replace enep = 2.820190306 if district_code == 35069
replace enep = 2.616910475 if district_code == 35070
replace enep = 2.775418672 if district_code == 35071
replace enep = 2.33303626 if district_code == 35072
replace enep = 2.432267433 if district_code == 35073
replace enep = 3.097509602 if district_code == 35074
replace enep = 2.836557554 if district_code == 35075
replace enep = 2.19222287 if district_code == 35076
replace enep = 2.300950523 if district_code == 35077
replace enep = 2.462144528 if district_code == 35078
replace enep = 2.421207844 if district_code == 35079
replace enep = 2.928909508 if district_code == 35080
replace enep = 2.809612245 if district_code == 35081
replace enep = 2.82323181 if district_code == 35082
replace enep = 2.86669304 if district_code == 35083
replace enep = 2.853050767 if district_code == 35084
replace enep = 2.451425013 if district_code == 35085
replace enep = 2.971326697 if district_code == 35086
replace enep = 2.414648222 if district_code == 35087
replace enep = 2.405349497 if district_code == 35088
replace enep = 2.809762238 if district_code == 35089
replace enep = 2.49241061 if district_code == 35090
replace enep = 3.10002542 if district_code == 35091
replace enep = 2.895244272 if district_code == 35092
replace enep = 2.379468046 if district_code == 35093
replace enep = 2.653843296 if district_code == 35094
replace enep = 2.256241328 if district_code == 35095
replace enep = 2.805064825 if district_code == 35096
replace enep = 2.228680443 if district_code == 35097
replace enep = 2.649610242 if district_code == 35098
replace enep = 2.649933222 if district_code == 35099
replace enep = 2.769722502 if district_code == 35100
replace enep = 2.507315092 if district_code == 35101
replace enep = 2.400649136 if district_code == 35102
replace enep = 2.878542767 if district_code == 35103
replace enep = 2.170996357 if district_code == 35104
replace enep = 3.039199596 if district_code == 35105
replace enep = 3.271394923 if district_code == 35106
replace enep = 2.8862861 if district_code == 35107
replace enep = 2.37203466 if district_code == 35108
replace enep = 2.831994744 if district_code == 35109
replace enep = 2.767821309 if district_code == 35110
replace enep = 2.312673451 if district_code == 35111
replace enep = 2.671054319 if district_code == 35112
replace enep = 2.49498508 if district_code == 35113
replace enep = 2.558526289 if district_code == 35114
replace enep = 2.339372814 if district_code == 35115
replace enep = 2.975915913 if district_code == 35116
replace enep = 2.699237465 if district_code == 35117
replace enep = 2.385416518 if district_code == 35118
replace enep = 2.476657503 if district_code == 35119
replace enep = 2.925208275 if district_code == 35120
replace enep = 1.99957609 if district_code == 35121
replace enep = 2.501075462 if district_code == 46001
replace enep = 2.34224401 if district_code == 46002
replace enep = 2.564668106 if district_code == 46003
replace enep = 3.081398215 if district_code == 46004
replace enep = 3.130066796 if district_code == 46005
replace enep = 2.765211428 if district_code == 46006
replace enep = 2.258886459 if district_code == 46007
replace enep = 2.275110969 if district_code == 46008
replace enep = 2.297846917 if district_code == 46009
replace enep = 2.614365415 if district_code == 46010
replace enep = 2.547465654 if district_code == 46011
replace enep = 1.935501353 if district_code == 46012
replace enep = 2.158712889 if district_code == 46013
replace enep = 2.247221311 if district_code == 46014
replace enep = 2.316884994 if district_code == 47001
replace enep = 1.925973291 if district_code == 47002
replace enep = 3.097797466 if district_code == 47003
replace enep = 2.10615883 if district_code == 47004
replace enep = 2.514945061 if district_code == 47005
replace enep = 2.71154086 if district_code == 47006
replace enep = 3.108582797 if district_code == 47007
replace enep = 2.910987815 if district_code == 47008
replace enep = 2.428793837 if district_code == 47009
replace enep = 2.991504128 if district_code == 47010
replace enep = 2.983444864 if district_code == 47011
replace enep = 3.072611966 if district_code == 47012
replace enep = 1.890105487 if district_code == 47013
replace enep = 2.359959975 if district_code == 47014
replace enep = 2.100200569 if district_code == 48001
replace enep = 1.495738641 if district_code == 48002
replace enep = 1.610217798 if district_code == 48003
replace enep = 2.352553697 if district_code == 48004
replace enep = 2.463205862 if district_code == 48005
replace enep = 2.695323344 if district_code == 48006
replace enep = 2.08144269 if district_code == 48007
replace enep = 1.98954692 if district_code == 48008
replace enep = 2.26713672 if district_code == 48009
replace enep = 2.131696191 if district_code == 48010
replace enep = 1.997642782 if district_code == 48011
replace enep = 2.15458269 if district_code == 48012
replace enep = 2.655365431 if district_code == 48013
replace enep = 3.109269042 if district_code == 48014
replace enep = 3.092193757 if district_code == 48015
replace enep = 2.9692093 if district_code == 48016
replace enep = 2.810899544 if district_code == 48017
replace enep = 2.702856108 if district_code == 48018
replace enep = 2.984940973 if district_code == 48019
replace enep = 2.616766671 if district_code == 48020
replace enep = 2.044254011 if district_code == 48021
replace enep = 1.677078529 if district_code == 48022
replace enep = 2.201397007 if district_code == 48023
replace enep = 1.783507196 if district_code == 48024
replace enep = 1.786977934 if district_code == 48025
replace enep = 2.501657348 if district_code == 48026
replace enep = 1.93960083 if district_code == 48027
replace enep = 1.925068629 if district_code == 48028
replace enep = 1.730669717 if district_code == 48029
replace enep = 1.86502445 if district_code == 48030
replace enep = 3.262876944 if district_code == 48031
replace enep = 2.170162437 if district_code == 48032
replace enep = 1.893362062 if district_code == 48033
replace enep = 1.811298882 if district_code == 48034
replace enep = 2.761317259 if district_code == 59001
replace enep = 3.354849099 if district_code == 59002
replace enep = 3.200327714 if district_code == 59003
replace enep = 3.320064144 if district_code == 59004
replace enep = 2.994280923 if district_code == 59005
replace enep = 3.043454443 if district_code == 59006
replace enep = 2.821200759 if district_code == 59007
replace enep = 3.297815857 if district_code == 59008
replace enep = 3.49770201 if district_code == 59009
replace enep = 3.757900987 if district_code == 59010
replace enep = 2.688967168 if district_code == 59011
replace enep = 2.835986399 if district_code == 59012
replace enep = 3.193000942 if district_code == 59013
replace enep = 2.552785216 if district_code == 59014
replace enep = 3.163976232 if district_code == 59015
replace enep = 2.781378117 if district_code == 59016
replace enep = 3.27641115 if district_code == 59017
replace enep = 3.854856927 if district_code == 59018
replace enep = 3.162365323 if district_code == 59019
replace enep = 3.204203916 if district_code == 59020
replace enep = 2.458041236 if district_code == 59021
replace enep = 3.300569678 if district_code == 59022
replace enep = 3.19217534 if district_code == 59023
replace enep = 2.74305527 if district_code == 59024
replace enep = 2.625871133 if district_code == 59025
replace enep = 3.734046287 if district_code == 59026
replace enep = 2.701629353 if district_code == 59027
replace enep = 2.783855863 if district_code == 59028
replace enep = 3.239453958 if district_code == 59029
replace enep = 2.646720977 if district_code == 59030
replace enep = 2.719815488 if district_code == 59031
replace enep = 2.98856277 if district_code == 59032
replace enep = 2.457884155 if district_code == 59033
replace enep = 2.58552931 if district_code == 59034
replace enep = 2.86717798 if district_code == 59035
replace enep = 2.992542584 if district_code == 59036
replace enep = 3.311291172 if district_code == 59037
replace enep = 3.016354675 if district_code == 59038
replace enep = 2.354137632 if district_code == 59039
replace enep = 2.678286861 if district_code == 59040
replace enep = 3.173797131 if district_code == 59041
replace enep = 2.600814055 if district_code == 59042
replace enep = 2.592486973 if district_code == 60001
replace enep = 2.77325583 if district_code == 61001
replace enep = 2.822259727 if district_code == 62001

* Boundary

gen boundary = .

replace boundary = 0 if district_code == 59041
replace boundary = 0 if district_code == 35007
replace boundary = 0 if district_code == 11001
replace boundary = 0 if district_code == 35032
replace boundary = 0 if district_code == 35072
replace boundary = 0 if district_code == 12011
replace boundary = 0 if district_code == 12010
replace boundary = 0 if district_code == 24056
replace boundary = 0 if district_code == 35091
replace boundary = 0 if district_code == 35102
replace boundary = 0 if district_code == 35024
replace boundary = 0 if district_code == 35121
replace boundary = 0 if district_code == 24051
replace boundary = 0 if district_code == 35018
replace boundary = 0 if district_code == 24038
replace boundary = 0 if district_code == 35083
replace boundary = 0 if district_code == 35120
replace boundary = 0 if district_code == 11002
replace boundary = 0 if district_code == 46002
replace boundary = 0 if district_code == 35086
replace boundary = 0 if district_code == 35109
replace boundary = 0 if district_code == 59035
replace boundary = 0 if district_code == 24067
replace boundary = 0 if district_code == 46011
replace boundary = 0 if district_code == 24058
replace boundary = 0 if district_code == 35022
replace boundary = 0 if district_code == 35082
replace boundary = 0 if district_code == 35081
replace boundary = 0 if district_code == 24066
replace boundary = 0 if district_code == 35050
replace boundary = 0 if district_code == 35040
replace boundary = 0 if district_code == 12007
replace boundary = 0 if district_code == 35067
replace boundary = 0 if district_code == 35113
replace boundary = 0 if district_code == 24025
replace boundary = 0 if district_code == 24009
replace boundary = 0 if district_code == 11003
replace boundary = 0 if district_code == 11004
replace boundary = 0 if district_code == 35014
replace boundary = 0 if district_code == 10004
replace boundary = 0 if district_code == 24018
replace boundary = 0 if district_code == 61001
replace boundary = 0 if district_code == 62001

replace boundary = 1 if boundary!=0 & district_code!=.

* Competition measure

gen competition = .

replace competition = .4283795 if district_code == 10001
replace competition = .2522675 if district_code == 10002
replace competition = .3003395 if district_code == 10003
replace competition = .325148 if district_code == 10004
replace competition = .3233915 if district_code == 10005
replace competition = .119774 if district_code == 10006
replace competition = .2300315 if district_code == 10007
replace competition = .389268 if district_code == 11001
replace competition = .39063 if district_code == 11002
replace competition = .3456155 if district_code == 11003
replace competition = .3995195 if district_code == 11004
replace competition = .31928 if district_code == 12001
replace competition = .3663995 if district_code == 12002
replace competition = .331228 if district_code == 12003
replace competition = .369294 if district_code == 12004
replace competition = .270212 if district_code == 12005
replace competition = .357988 if district_code == 12006
replace competition = .3380255 if district_code == 12007
replace competition = .29711 if district_code == 12008
replace competition = .3833255 if district_code == 12009
replace competition = .3297835 if district_code == 12010
replace competition = .3384015 if district_code == 12011
replace competition = .2200335 if district_code == 13001
replace competition = .3585955 if district_code == 13002
replace competition = .3779935 if district_code == 13003
replace competition = .269632 if district_code == 13004
replace competition = .358264 if district_code == 13005
replace competition = .29902 if district_code == 13006
replace competition = .3894455 if district_code == 13007
replace competition = .2515495 if district_code == 13008
replace competition = .3365335 if district_code == 13009
replace competition = .272852 if district_code == 13010
replace competition = .3593135 if district_code == 24001
replace competition = .3766535 if district_code == 24002
replace competition = .37445 if district_code == 24003
replace competition = .4315495 if district_code == 24004
replace competition = .4248315 if district_code == 24005
replace competition = .4749755 if district_code == 24006
replace competition = .397216 if district_code == 24007
replace competition = .4140035 if district_code == 24008
replace competition = .4243455 if district_code == 24009
replace competition = .44421 if district_code == 24010
replace competition = .355294 if district_code == 24011
replace competition = .410686 if district_code == 24012
replace competition = .396682 if district_code == 24013
replace competition = .4009615 if district_code == 24014
replace competition = .453808 if district_code == 24015
replace competition = .430356 if district_code == 24016
replace competition = .4164975 if district_code == 24017
replace competition = .3900295 if district_code == 24018
replace competition = .435274 if district_code == 24019
replace competition = .409816 if district_code == 24020
replace competition = .4200735 if district_code == 24021
replace competition = .37944 if district_code == 24022
replace competition = .4060935 if district_code == 24023
replace competition = .4248035 if district_code == 24024
replace competition = .404972 if district_code == 24025
replace competition = .335696 if district_code == 24026
replace competition = .388838 if district_code == 24027
replace competition = .35123 if district_code == 24028
replace competition = .4382055 if district_code == 24029
replace competition = .3461435 if district_code == 24030
replace competition = .3794675 if district_code == 24031
replace competition = .3838055 if district_code == 24032
replace competition = .366822 if district_code == 24033
replace competition = .4097895 if district_code == 24034
replace competition = .392524 if district_code == 24035
replace competition = .3859955 if district_code == 24036
replace competition = .3868295 if district_code == 24037
replace competition = .354948 if district_code == 24038
replace competition = .378228 if district_code == 24039
replace competition = .4483015 if district_code == 24040
replace competition = .401306 if district_code == 24041
replace competition = .436038 if district_code == 24042
replace competition = .348464 if district_code == 24043
replace competition = .408886 if district_code == 24044
replace competition = .4340655 if district_code == 24045
replace competition = .3845675 if district_code == 24046
replace competition = .3929735 if district_code == 24047
replace competition = .353088 if district_code == 24048
replace competition = .3861735 if district_code == 24049
replace competition = .3972995 if district_code == 24050
replace competition = .38205 if district_code == 24051
replace competition = .250656 if district_code == 24052
replace competition = .4003175 if district_code == 24053
replace competition = .347096 if district_code == 24054
replace competition = .4062075 if district_code == 24055
replace competition = .3959235 if district_code == 24056
replace competition = .412792 if district_code == 24057
replace competition = .4328415 if district_code == 24058
replace competition = .4060755 if district_code == 24059
replace competition = .404776 if district_code == 24060
replace competition = .4181295 if district_code == 24061
replace competition = .3651295 if district_code == 24062
replace competition = .3529755 if district_code == 24063
replace competition = .4294415 if district_code == 24064
replace competition = .42819 if district_code == 24065
replace competition = .3921035 if district_code == 24066
replace competition = .3710795 if district_code == 24067
replace competition = .3977915 if district_code == 24068
replace competition = .3975155 if district_code == 24069
replace competition = .4529415 if district_code == 24070
replace competition = .350646 if district_code == 24071
replace competition = .4309695 if district_code == 24072
replace competition = .3817 if district_code == 24073
replace competition = .4414615 if district_code == 24074
replace competition = .378744 if district_code == 24075
replace competition = .378822 if district_code == 24076
replace competition = .434202 if district_code == 24077
replace competition = .453156 if district_code == 24078
replace competition = .2748735 if district_code == 35001
replace competition = .28145 if district_code == 35002
replace competition = .1217855 if district_code == 35003
replace competition = .2717955 if district_code == 35004
replace competition = .2106015 if district_code == 35005
replace competition = .294932 if district_code == 35006
replace competition = .33677 if district_code == 35007
replace competition = .3027455 if district_code == 35008
replace competition = .362036 if district_code == 35009
replace competition = .308162 if district_code == 35010
replace competition = .2810135 if district_code == 35011
replace competition = .324252 if district_code == 35012
replace competition = .323896 if district_code == 35013
replace competition = .2404715 if district_code == 35014
replace competition = .1779235 if district_code == 35015
replace competition = .25109 if district_code == 35016
replace competition = .2585495 if district_code == 35017
replace competition = .2048355 if district_code == 35018
replace competition = .33059 if district_code == 35019
replace competition = .242566 if district_code == 35020
replace competition = .239266 if district_code == 35021
replace competition = .24333 if district_code == 35022
replace competition = .2823255 if district_code == 35023
replace competition = .1691535 if district_code == 35024
replace competition = .339704 if district_code == 35025
replace competition = .2698915 if district_code == 35026
replace competition = .2462835 if district_code == 35027
replace competition = .3119935 if district_code == 35028
replace competition = .358438 if district_code == 35029
replace competition = .238758 if district_code == 35030
replace competition = .2590255 if district_code == 35031
replace competition = .403208 if district_code == 35032
replace competition = .2860255 if district_code == 35033
replace competition = .32783 if district_code == 35034
replace competition = .32781 if district_code == 35035
replace competition = .2962674 if district_code == 35036
replace competition = .294302 if district_code == 35037
replace competition = .3309455 if district_code == 35038
replace competition = .1924255 if district_code == 35039
replace competition = .225478 if district_code == 35040
replace competition = .2221455 if district_code == 35041
replace competition = .260018 if district_code == 35042
replace competition = .141588 if district_code == 35043
replace competition = .3920775 if district_code == 35044
replace competition = .345998 if district_code == 35045
replace competition = .1829515 if district_code == 35046
replace competition = .283124 if district_code == 35047
replace competition = .346518 if district_code == 35048
replace competition = .3107615 if district_code == 35049
replace competition = .212166 if district_code == 35050
replace competition = .304038 if district_code == 35051
replace competition = .334922 if district_code == 35052
replace competition = .2931495 if district_code == 35053
replace competition = .16342 if district_code == 35054
replace competition = .299778 if district_code == 35055
replace competition = .1534915 if district_code == 35056
replace competition = .218298 if district_code == 35057
replace competition = .2914295 if district_code == 35058
replace competition = .268436 if district_code == 35059
replace competition = .2234755 if district_code == 35060
replace competition = .1998895 if district_code == 35061
replace competition = .3487575 if district_code == 35062
replace competition = .212522 if district_code == 35063
replace competition = .2679895 if district_code == 35064
replace competition = .18177 if district_code == 35065
replace competition = .28704 if district_code == 35066
replace competition = .28745 if district_code == 35067
replace competition = .3357675 if district_code == 35068
replace competition = .252946 if district_code == 35069
replace competition = .342924 if district_code == 35070
replace competition = .2297175 if district_code == 35071
replace competition = .1689395 if district_code == 35072
replace competition = .162322 if district_code == 35073
replace competition = .2936835 if district_code == 35074
replace competition = .252696 if district_code == 35075
replace competition = .30687 if district_code == 35076
replace competition = .3681141 if district_code == 35077
replace competition = .393524 if district_code == 35078
replace competition = .3348875 if district_code == 35079
replace competition = .3362375 if district_code == 35080
replace competition = .228796 if district_code == 35081
replace competition = .254602 if district_code == 35082
replace competition = .2665095 if district_code == 35083
replace competition = .2843995 if district_code == 35084
replace competition = .2403455 if district_code == 35085
replace competition = .3453475 if district_code == 35086
replace competition = .158996 if district_code == 35087
replace competition = .15493 if district_code == 35088
replace competition = .255876 if district_code == 35089
replace competition = .3576375 if district_code == 35090
replace competition = .3034675 if district_code == 35091
replace competition = .3217355 if district_code == 35092
replace competition = .2390375 if district_code == 35093
replace competition = .324584 if district_code == 35094
replace competition = .3439575 if district_code == 35095
replace competition = .35202 if district_code == 35096
replace competition = .335624 if district_code == 35097
replace competition = .37395 if district_code == 35098
replace competition = .250376 if district_code == 35099
replace competition = .2401715 if district_code == 35100
replace competition = .354214 if district_code == 35101
replace competition = .233196 if district_code == 35102
replace competition = .359348 if district_code == 35103
replace competition = .274804 if district_code == 35104
replace competition = .3504075 if district_code == 35105
replace competition = .428878 if district_code == 35106
replace competition = .283788 if district_code == 35107
replace competition = .3568395 if district_code == 35108
replace competition = .2389215 if district_code == 35109
replace competition = .357946 if district_code == 35110
replace competition = .145386 if district_code == 35111
replace competition = .320112 if district_code == 35112
replace competition = .269186 if district_code == 35113
replace competition = .1873795 if district_code == 35114
replace competition = .250934 if district_code == 35115
replace competition = .339588 if district_code == 35116
replace competition = .3678275 if district_code == 35117
replace competition = .1465735 if district_code == 35118
replace competition = .24878 if district_code == 35119
replace competition = .34532 if district_code == 35120
replace competition = .3503655 if district_code == 35121
replace competition = .259912 if district_code == 46001
replace competition = .222468 if district_code == 46002
replace competition = .189722 if district_code == 46003
replace competition = .38657 if district_code == 46004
replace competition = .2530975 if district_code == 46005
replace competition = .2284655 if district_code == 46006
replace competition = .359686 if district_code == 46007
replace competition = .274466 if district_code == 46008
replace competition = .3321275 if district_code == 46009
replace competition = .3362055 if district_code == 46010
replace competition = .3623435 if district_code == 46011
replace competition = .35147 if district_code == 46012
replace competition = .261452 if district_code == 46013
replace competition = .3337175 if district_code == 46014
replace competition = .393794 if district_code == 47001
replace competition = .3513675 if district_code == 47002
replace competition = .2478035 if district_code == 47003
replace competition = .364822 if district_code == 47004
replace competition = .3750595 if district_code == 47005
replace competition = .3442355 if district_code == 47006
replace competition = .2539235 if district_code == 47007
replace competition = .3275535 if district_code == 47008
replace competition = .326996 if district_code == 47009
replace competition = .312054 if district_code == 47010
replace competition = .303084 if district_code == 47011
replace competition = .2979755 if district_code == 47012
replace competition = .345612 if district_code == 47013
replace competition = .380406 if district_code == 47014
replace competition = .3355575 if district_code == 48001
replace competition = .2647175 if district_code == 48002
replace competition = .2976995 if district_code == 48003
replace competition = .123238 if district_code == 48004
replace competition = .161124 if district_code == 48005
replace competition = .292574 if district_code == 48006
replace competition = .332774 if district_code == 48007
replace competition = .3397835 if district_code == 48008
replace competition = .3475495 if district_code == 48009
replace competition = .2897275 if district_code == 48010
replace competition = .32951 if district_code == 48011
replace competition = .306218 if district_code == 48012
replace competition = .2378095 if district_code == 48013
replace competition = .273288 if district_code == 48014
replace competition = .30241 if district_code == 48015
replace competition = .35554 if district_code == 48016
replace competition = .2164716 if district_code == 48017
replace competition = .3391395 if district_code == 48018
replace competition = .3336056 if district_code == 48019
replace competition = .289428 if district_code == 48020
replace competition = .3529515 if district_code == 48021
replace competition = .3149835 if district_code == 48022
replace competition = .330116 if district_code == 48023
replace competition = .333134 if district_code == 48024
replace competition = .3336195 if district_code == 48025
replace competition = .3943935 if district_code == 48026
replace competition = .3525075 if district_code == 48027
replace competition = .354098 if district_code == 48028
replace competition = .3235355 if district_code == 48029
replace competition = .3437015 if district_code == 48030
replace competition = .4313875 if district_code == 48031
replace competition = .3779395 if district_code == 48032
replace competition = .350228 if district_code == 48033
replace competition = .3399975 if district_code == 48034
replace competition = .3247735 if district_code == 59001
replace competition = .3338775 if district_code == 59002
replace competition = .276394 if district_code == 59003
replace competition = .3227135 if district_code == 59004
replace competition = .261404 if district_code == 59005
replace competition = .3165975 if district_code == 59006
replace competition = .2989075 if district_code == 59007
replace competition = .3067115 if district_code == 59008
replace competition = .3821175 if district_code == 59009
replace competition = .4197295 if district_code == 59010
replace competition = .3155975 if district_code == 59011
replace competition = .339212 if district_code == 59012
replace competition = .2923355 if district_code == 59013
replace competition = .212382 if district_code == 59014
replace competition = .274644 if district_code == 59015
replace competition = .281754 if district_code == 59016
replace competition = .3035795 if district_code == 59017
replace competition = .4144175 if district_code == 59018
replace competition = .3739995 if district_code == 59019
replace competition = .3343 if district_code == 59020
replace competition = .36692 if district_code == 59021
replace competition = .2970735 if district_code == 59022
replace competition = .2968675 if district_code == 59023
replace competition = .398048 if district_code == 59024
replace competition = .200684 if district_code == 59025
replace competition = .3945 if district_code == 59026
replace competition = .4221775 if district_code == 59027
replace competition = .3897295 if district_code == 59028
replace competition = .3225575 if district_code == 59029
replace competition = .2037355 if district_code == 59030
replace competition = .25128 if district_code == 59031
replace competition = .351334 if district_code == 59032
replace competition = .3582915 if district_code == 59033
replace competition = .4102455 if district_code == 59034
replace competition = .3874075 if district_code == 59035
replace competition = .348664 if district_code == 59036
replace competition = .378414 if district_code == 59037
replace competition = .3711255 if district_code == 59038
replace competition = .3629495 if district_code == 59039
replace competition = .3059415 if district_code == 59040
replace competition = .34728 if district_code == 59041
replace competition = .383914 if district_code == 59042
replace competition = .37206 if district_code == 60001
replace competition = .334562 if district_code == 61001
replace competition = .3455175 if district_code == 62001


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen time = 0

* Province

gen province = prov

* Language

gen language = lang

recode language 1=0 2=1

label define language 0 "English" 1 "French"
label values language language

* Gender

gen male = gender

recode male 2=0

label define gender 0 "Female" 1 "Male"
label values male gender

* Age

gen r_age = ageval

replace r_age = . if r_age < 17

* Age 55 and over

gen age55 = 1 if r_age >= 55
replace age55 = 0 if r_age < 55 & r_age!=.

label define age55 0 "Less than 55" 1 "55 and over"
label values age55 age55

* Education

gen education = caedu2

label define education 1 "Primary school or less" 2 "Some high school" 3 "High school" 4 "Some community college/CEGEP/Trade school" 5 "Community college/CEGEP/Trade school" 6 "Some university" 7 "University undergraduate degree" 8 "University graduate degree"
label values education education

* Education (uniform)

gen education_unif = education
recode education_unif 1=771 2=771 3=772 4=772 5=773 6=774 7=775 8=776

label define education_unif 771 "Some high school" 772 "High school" 773 "Community college/CEGEP/Trade school" 774 "Some university" 775 "University undergraduate degree" 776 "University graduate degree"
label values education_unif education_unif

* University degree

gen univ = 1 if education >= 7
replace univ = 0 if education < 7 & education!=.

label define univ 0 "No university degree" 1 "University degree"
label values univ univ

* Postgraduate degree

gen postgrad = 1 if education == 8
replace postgrad = 0 if education < 8 & education!=.

label define postgrad 0 "No postgraduate degree" 1 "Postgraduate degree"
label values postgrad postgrad

* Postsecondary degree

gen postsec = 1 if education >= 5
replace postsec = 0 if education < 5 & education!=.

label define postsec 0 "No postsecondary" 1 "Postsecondary"
label values postsec postsec

* Immigrant

gen immigrant = qd1

recode immigrant 1=0 2=1

label define immigrant 0 "Born in Canada" 1 "Immigrant"
label values immigrant immigrant

* Visible minority

gen minority = qd11

recode minority 2=0

label define minority 0 "Not visible minority" 1 "Visible minority"
label values minority minority

* Household income

gen income = ushhi2

recode income 24=.

label define income 1 "Less than $5,000" 2 "$5,000-$9,999" 3 "$10,000-$14,999" 4 "$15,000-$19,999" 5 "$20,000-$24,999" 6 "$25,000-$29,999" 7 "$30,000-$34,999" 8 "$35,000-$39,999" 9 "$40,000-$44,999" 10 "$45,000-$49,999" 11 "$50,000-$54,999" 12 "$55,000-$59,999" 13 "$60,000-$64,999" 14 "$65,000-$69,999" 15 "$70,000-$74,999" 16 "$75,000-$79,999" 17 "$80,000-$89,999" 18 "$90,000-$99,999" 19 "$100,000-$124,999" 20 "$125,000-$149,999" 21 "$150,000-199,999$" 22 "$200,000-249,999$" 23 "$250,000 or more"
label values income income

* Household income (uniform)

gen income_unif = income
recode income_unif 1=771 2=771 3=771 4=771 5=772 6=772 7=772 8=772 9=773 10=773 11=773 12=773 13=774 14=774 15=774 16=774 17=775 18=775 19=776 20=776 21=776 22=776 23=776

* Household income (quintile)

xtile income5 = income, nq(5)

* Highest income categories

gen highinc = 1 if income5 == 5
replace highinc = 0 if income5 < 5 & income!=.

label define highinc 0 "Others" 1 "Highest incomes"
label values highinc highinc

* Vote choice

gen vote_choice = q2

recode vote_choice 6=88

label define vote_choice 1 "Conservative Party of Canada" 2 "Liberal Party of Canada" 3 "New Democratic Party of Canada" 4 "Bloc Quebecois" 5 "Green Party of Canada" 88 "Other party"
label values vote_choice vote_choice

* Vote status (district)

gen vote_district = 1 if vote_choice == district_outcome
replace vote_district = 0 if vote_choice!=district_outcome & vote_choice!=. 

label define winner 0 "Voted for loser" 1 "Voted for winner"
label values vote_district winner

* Vote status (national)

gen vote_whole = 1 if decided == 2
replace vote_whole = 0 if decided!=2 & decided!=. 

label values vote_whole winner

* Previous vote

gen voted_prev = q4

gen remember = q5

gen vote_prev = q6

recode vote_prev 7=.

gen prev = 1 if decided == vote_prev & vote_prev!=.
replace prev = 0 if decided!=vote_prev & vote_prev!=.
replace prev = 888 if remember == 2
replace prev = 999 if voted_prev == 2 | voted_prev == 3

label define prev 0 "Changed vote" 1 "Same vote" 888 "Don't remember" 999 "Did not vote/Not sure"
label values prev prev

* When did you decide who you were going to vote for today?

gen decide = q7

recode decide 6=. 5=1 4=2 2=4 1=5


*********************************
** DISTRICT-LEVEL EXPECTATIONS **
*********************************

* Forecasts

gen forecast_district = q10a

recode forecast_district 5=88 6=-99

label define forecast 1 "Conservative Party of Canada" 2 "Liberal Party of Canada" 3 "New Democratic Party of Canada" 4 "Bloc Québécois" 88 "Other" -99 "Don't know"
label values forecast_district forecast

* Identify correct forecasts

gen correct_district = 0 if forecast_district!=district_outcome & forecast_district!=.
replace correct_district = 1 if forecast_district == district_outcome

label define correct 0 "Incorrect" 1 "Correct"
label values correct_district correct


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts

gen forecast_whole = q10b

recode forecast_whole 4=-99

label values forecast_whole forecast

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=2 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 2


*************
** WEIGHTS **
*************

* Sex

gen sex_ca2015_w = male

recode sex_ca2015_w 0=1 1=2

label define sex_ca2015_w 1 "Female" 2 "Male"
label values sex_ca2015_w sex_ca2015_w

* Age

gen age_ca2015_w = ageval

replace age_ca2015_w = 1 if age_ca2015_w >= 18 & age_ca2015_w <= 19
replace age_ca2015_w = 2 if age_ca2015_w >= 20 & age_ca2015_w <= 24
replace age_ca2015_w = 3 if age_ca2015_w >= 25 & age_ca2015_w <= 29
replace age_ca2015_w = 4 if age_ca2015_w >= 30 & age_ca2015_w <= 34
replace age_ca2015_w = 5 if age_ca2015_w >= 35 & age_ca2015_w <= 39
replace age_ca2015_w = 6 if age_ca2015_w >= 40 & age_ca2015_w <= 44
replace age_ca2015_w = 7 if age_ca2015_w >= 45 & age_ca2015_w <= 49
replace age_ca2015_w = 8 if age_ca2015_w >= 50 & age_ca2015_w <= 54
replace age_ca2015_w = 9 if age_ca2015_w >= 55 & age_ca2015_w <= 59
replace age_ca2015_w = 10 if age_ca2015_w >= 60 & age_ca2015_w <= 64
replace age_ca2015_w = 11 if age_ca2015_w >= 65 & age_ca2015_w <= 69
replace age_ca2015_w = 12 if age_ca2015_w >= 70 & age_ca2015_w <= 74
replace age_ca2015_w = 13 if age_ca2015_w >= 75 & age_ca2015_w <= 79
replace age_ca2015_w = 14 if age_ca2015_w >= 80 & age_ca2015_w <= 84
replace age_ca2015_w = 15 if age_ca2015_w >= 85

label define age_ca2015_w 1 "18-19" 2 "20-24" 3 "25-29" 4 "30-34" 5 "35-39" 6 "40-44" 7 "45-49" 8 "50-54" 9 "55-59" 10 "60-64" 11 "65-69" 12 "70-74" 13 "75-79" 14 "80-84" 15 "85+"
label values age_ca2015_w age_ca2015_w

* Education

gen education_ca2015_w = education

recode education_ca2015_w 2=1 3=2 4=2 5=3 6=3 7=4 8=5

label define education_ca2015_w 1 "Below high school" 2 "High school" 3 "Postsecondary below bachelor" 4 "University undergraduate degree" 5 "University graduate degree"
label values education_ca2015_w education_ca2015_w

* Province

gen province_ca2015_w = province

replace province_ca2015_w = 10 if province == 1
replace province_ca2015_w = 9 if province == 2
replace province_ca2015_w = 8 if province == 3
replace province_ca2015_w = 7 if province == 4
replace province_ca2015_w = 6 if province == 5
replace province_ca2015_w = 5 if province == 6
replace province_ca2015_w = 4 if province == 7
replace province_ca2015_w = 3 if province == 8
replace province_ca2015_w = 2 if province == 9
replace province_ca2015_w = 1 if province == 10

label define province_ca2015_w 1 "Newfoundland and Labrador" 2 "Prince Edward Island" 3 "Nova Scotia" 4 "New Brunswick" 5 "Quebec" 6 "Ontario" 7 "Manitoba" 8 "Saskatchewan" 9 "Alberta" 10 "British Columbia"
label values province_ca2015_w province_ca2015_w

* Income

gen income_ca2015_w = ushhi2

recode income_ca2015_w 2/4=1 5/8=2 9/12=3 13/16=4 17/18=5 19/20=6 21=7 22/23=8 24=.

label define income_ca2015_w 1 "Less than $20,000" 2 "$20,000-$39,999" 3 "$40,000-$59,999" 4 "$60,000-$79,999" 5 "$80,000-$99,999" 6 "$100,000-$149,999" 7 "$150,000-$199,999" 8 "$200,000 or more"
label values income_ca2015_w income_ca2015_w


**********
** SAVE **
**********

save "ca2015_ipsos_exit.dta", replace

log close